package cn.iocoder.yudao.module.of.controller.admin.taskfeedback;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.IdReq;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.of.controller.admin.taskfeedback.vo.*;
import cn.iocoder.yudao.module.of.service.taskfeedback.TaskFeedbackService;
import cn.iocoder.yudao.module.of.service.taskhandler.TaskHandlerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 任务反馈")
@RestController
@RequestMapping("/of/task-feedback")
@Validated
public class TaskFeedbackController {

    @Resource
    private TaskFeedbackService taskFeedbackService;
    @Resource
    private TaskHandlerService taskHandlerService;

    @PostMapping("/feedbackPage")
    @Operation(summary = "获取反馈分页")
    public CommonResult<PageResult<?>> getPage(@Valid @RequestBody TaskFeedbackPageReqVO req) {
        PageResult<?> page = taskFeedbackService.feedbackPage(req);
        return success(page);
    }

    @PostMapping("/getDetail")
    @Operation(summary = "获得任务反馈详情(全部)")
    public CommonResult<TaskFeedbackDetailVO> getTaskFeedbackDetail(@Valid @RequestBody IdReq req) {

        TaskFeedbackDetailVO taskFeedbackDetail = taskFeedbackService.getTaskFeedbackDetail(req.getId());
        return success(taskFeedbackDetail);
    }

    @PostMapping("/getFeedbackInfo")
    @Operation(summary = "获得任务反馈详情(单任务)")
    public CommonResult<List<TaskFeedbackSampleVO>> getTaskFeedbackInfo(@Valid @RequestBody IdReq req) {

        List<TaskFeedbackSampleVO> res = taskFeedbackService.getTaskFeedbackInfo(req.getId());
        return success(res);
    }

    @PostMapping("/submit")
    @Operation(summary = "任务反馈")
    public CommonResult<Boolean> createTaskFeedback(@Valid @RequestBody TaskFeedbackSaveReqVO createReqVO) {

        taskFeedbackService.submitTaskFeedback(createReqVO);
        return success(true);
    }

    @PostMapping("/approval")
    @Operation(summary = "反馈审核(子)、确认(主)")
    public CommonResult<Boolean> approval(@Valid @RequestBody TaskFeedbackApprovalReqVO req) {

        taskFeedbackService.approval(req);
        return success(true);
    }

    @PostMapping("/approval2")
    @Operation(summary = "二次审核")
    public CommonResult<Boolean> approval2(@Valid @RequestBody TaskFeedbackApprovalReqVO req) {

        taskFeedbackService.approval2(req);
        return success(true);
    }

    @PostMapping("/addTaskInterfaceUser")
    @Operation(summary = "集团部门领导添加任务办理人")
    public CommonResult<Boolean> approval2(@Valid @RequestBody AddTaskInterfaceUserReq req) {

        taskHandlerService.addTaskInterfaceUser(req);
        return success(true);
    }

}